using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WPCoco;

namespace WPCoco.Tasks
{
    /// <summary>
    /// Base class for tasks
    /// </summary>
    public abstract class Task : IDictionarySerializable
    {
        /// <summary>
        /// Time when the task was scheduled
        /// </summary>
        public float StartTime { get; set; }

        /// <summary>
        /// Owner object
        /// </summary>
        public object Owner{ get; set; }

        /// <summary>
        /// Key for the task
        /// </summary>
        public int Key { get; set; }

        /// <summary>
        /// This method is called once before the task start
        /// </summary>
        public virtual void Initialize() 
        {
            isStoped = false;
        }

        /// <summary>
        /// Overrid for add some logic for the task
        /// </summary>
        /// <param name="time"></param>
        public abstract void Update(float time);
        
        /// <summary>
        /// Return true if the task has finished his job
        /// </summary>
        /// <returns></returns>
        public abstract bool HasEnded();

        /// <summary>
        /// Called once after the task finish hist job
        /// </summary>
        public abstract void Finish();

        bool isStoped;
        /// <summary>
        /// True if its stoped
        /// </summary>
        public bool IsStoped
        {
            get { return isStoped; }
            private set { isStoped = value; }
        }

        /// <summary>
        /// Call for stop the task
        /// </summary>
        public void Stop() 
        {
            isStoped = true;
        }

        /// <summary>
        /// Create a clone copy of the task
        /// </summary>
        /// <returns></returns>
        public abstract Task Clone();

        /// <summary>
        /// Create a reverse copy of the task
        /// </summary>
        public abstract Task Reverse();

        #region IDictionarySerializable
        /// <summary>
        /// Return an dictionary that contain all data for the task
        /// </summary>
        /// <returns></returns>
        public virtual IDictionary<string, object> GetDictionary()
        {
            return null;
        }

        /// <summary>
        /// Load the task data from one dictionary
        /// </summary>
        /// <param name="data"></param>
        public void FromDictionary(IDictionary<string, object> data)
        {
            
        }

        #endregion
    }
}
